<template>
  <div class="detail">
    <van-nav-bar title="文章详情" left-arrow @click-left="$router.back()" />
    <!-- 标题 -->
    <h2 class="title">{{ detail.title }}</h2>
    <!-- 作者信息 -->
    <div class="author-box">
      <van-image round fit="cover" :src="detail.aut_photo"></van-image>
      <div class="info">
        <div class="name">{{ detail.aut_name }}</div>
        <div class="time">{{ detail.pubdate | relvTime }}</div>
      </div>
      <van-button icon="plus" size="small" round type="info">关注</van-button>
    </div>
    <!-- 内容 -->
    <div class="content" v-html="detail.content"></div>

    <van-divider>end</van-divider>

    <div class="tool-box">
      <van-button plain round type="primary" icon="good-job-o">点赞</van-button>
      <van-button plain round type="danger" icon="delete-o">不喜欢</van-button>
    </div>

    <!-- 评论区域 -->
    <comment />
  </div>
</template>

<script>
import { artDetailAPI } from "@/api";

import comment from "./comment";

export default {
  components: {
    comment
  },
  data() {
    return {
      detail: {},
    };
  },

  async created() {
    // 拿到路由传递的数据用$route
    let res = await artDetailAPI(this.$route.query.id);
    this.detail = res.data.data;
  },
};
</script>

<style lang="less" scoped>
.title {
  margin-top: 10px;
  margin-left: 15px;
}
.author-box {
  display: flex;
  margin: 20px 0;
  align-items: center;

  .van-image {
    width: 60px;
    height: 60px;
    margin: 0 15px;
  }

  .info {
    flex: 1;
    .time {
      color: #ccc;
    }
  }

  .van-button {
    margin-right: 15px;
  }
}
.content {
  margin: 0px 15px;
  overflow: hidden;

  ::v-deep pre {
    overflow: auto;
    background-color: #000;
    color: #fff;
  }

  ::v-deep {
    img {
      width: 100%;
    }
  }
}

.tool-box {
  display: flex;
  justify-content: space-around;

  .van-button {
    width: 120px;
  }
}
</style>